PCA Index Interactive Visualization Examples

PCA Index Interactive Visualization Examples#

import plotly.express as px

import config
import load_fred
import pca_index

DATA_DIR = config.DATA_DIR

import warnings
warnings.filterwarnings('ignore')
df = load_fred.load_fred(data_dir=DATA_DIR)
dfn = pca_index.transform_series(df)
## Visualize Principal Component 1
pc1, loadings = pca_index.pca(dfn, module="scikitlearn")
pc1.plot(color="red")
<Axes: xlabel='DATE'>
../_images/625006444b5dee2810d7bca9227ec749bf896bc02fb849883b0582f2e36a42d6.png
# Simple version
fig = px.line(pc1)
fig.show()
# Using slider and quick views
pca_index.pc1_line_plot(pc1)
## Visualize normalized and raw series
dfn.plot(subplots=True, figsize=(10, 10));
../_images/00fedc17adb30a93f9ab4ab7d74f1b45c8ac639439e3f8254ed95f07c88c2b97.png
fig = px.line(dfn, facet_col="variable", facet_col_wrap=1)
fig.update_yaxes(matches=None)
fig.show()
pca_index.plot_unnormalized_series(df)
pca_index.plot_normalized_series(dfn)